package Threadprojects.pro2_knn.grounp;

import Threadprojects.pro2_knn.util.DistanceCalculator;
import Threadprojects.pro2_knn.util.EuclideDistanceCalculate;
import Threadprojects.pro2_knn.bean.BankMarketing;
import Threadprojects.pro2_knn.bean.Distance;
import Threadprojects.pro2_knn.bean.Sample;

import java.util.List;

public class GrounpDistanceTask implements Runnable{
    Distance[] distances;
    int startIndex;
    int endIndex;
    List<BankMarketing> dataset;
    Sample example;
    DistanceCalculator edc=new EuclideDistanceCalculate();

    public GrounpDistanceTask(Distance[] distances, int startIndex, int endIndex, List<BankMarketing> dataset, Sample example) {
        this.distances = distances;
        this.startIndex = startIndex;
        this.endIndex = endIndex;
        this.dataset = dataset;
        this.example = example;
    }

    public GrounpDistanceTask(Distance[] distances, int startIndex, int endIndex, List<BankMarketing> dataset, Sample example, DistanceCalculator edc) {
        this.distances = distances;
        this.startIndex = startIndex;
        this.endIndex = endIndex;
        this.dataset = dataset;
        this.example = example;
        this.edc = edc;
    }

    @Override
    public void run() {
        for (int i = startIndex; i < endIndex; i++) {
            Sample sample = dataset.get(i);
            //计算sample与测试数据example的距离
            distances[i] = new Distance();
            distances[i].setIndex(i);
            distances[i].setDistance(this.edc.calculate(sample,example));
        }
    }
}
